using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Ninject;
using SomeRandomGame.Graphics;
using SomeRandomGame.Interfaces;
using SomeRandomGame.Screens;
using SomeRandomGame.Ships;
using SomeRandomGame.Utility;

namespace SomeRandomGame
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class GameManager: Microsoft.Xna.Framework.Game, IGameManager
    {
        private GraphicsDeviceManager graphicsDeviceManager;
        private SpriteBatch _mainSpriteBatch;
        private GameTime _gameTime;
        private IKernel _kernel;
        private IScreenManager _screenManager;
        private AchievementManager _achievementManager;

        public Game Game
        {
            get { return this; }
        }

        public GameTime GameTime { get { return _gameTime; } }

        public IKernel ServiceLocator { get { return _kernel; } }

        public GameManager()
        {
            graphicsDeviceManager = new GraphicsDeviceManager( this );
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            _mainSpriteBatch = new SpriteBatch( GraphicsDevice );
            _kernel = Bootstrapper.Bootstrap( this );

            _screenManager = _kernel.Get<IScreenManager>();
            _screenManager.AddScreen( this, new BackgroundScreen(), null );
            _screenManager.AddScreen( this, new MainMenuScreen( this ), null );

            _screenManager.Initialize( this );

            _achievementManager = new AchievementManager(_screenManager);

            base.Initialize();
        }

        protected override void Update( GameTime gameTime )
        {
            _gameTime = gameTime;
            _screenManager.Update( this );
            base.Update( gameTime );
        }

        protected override void Draw( GameTime gameTime )
        {
            _gameTime = gameTime;

            GraphicsDevice.Clear( Color.CornflowerBlue );

            _screenManager.Draw( _mainSpriteBatch, this, gameTime );
            base.Draw( gameTime );
        }
    }
}
